﻿using mBlog.Data.Entities;

namespace mBlog.Core
{
    public static class ModelEntityMapperConfiguration
    {
        public static void Init()
        {
            //mapping from entity to model
            AutoMapper.Mapper.CreateMap<Comment, mBlog.Core.Models.Comment>();
            AutoMapper.Mapper.CreateMap<Category, mBlog.Core.Models.Category>()
                .ForMember(c => c.Posts, opt => opt.Ignore());
            AutoMapper.Mapper.CreateMap<Tag, mBlog.Core.Models.Tag>()
                .ForMember(t => t.Posts, opt => opt.Ignore());

            AutoMapper.Mapper.CreateMap<Post, mBlog.Core.Models.Post>();

            //models to entities
            AutoMapper.Mapper.CreateMap<Models.Comment, Comment>();
            AutoMapper.Mapper.CreateMap<Models.Tag, Tag>()
                .ForMember(t => t.Posts, opt => opt.Ignore());
            AutoMapper.Mapper.CreateMap<Models.Category, Category>()
                .ForMember(p => p.Posts, opt => opt.Ignore());

            //only mapping post content
            AutoMapper.Mapper.CreateMap<Models.Post, Post>()
                .ForMember(c => c.Comments, opt => opt.Ignore())
                .ForMember(c => c.Categories, opt => opt.Ignore())
                .ForMember(c => c.Tags, opt => opt.Ignore()) ;
        }
    }
}
